package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.TItempic;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.TItempicDao;
import com.ruipengkj.service.TItempicService;
@Service
public class TItempicServiceImpl implements TItempicService {

	@Resource
	private TItempicDao TItempicDao;
	//查询所有
	@Override
	public List<TItempic> findService(TItempic entity) throws Exception {
		String hql = "select o from TItempic o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TItempicDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
	//根据ID翻页查询
	@Override
	public PageModel<TItempic> getScrollService(int firstResult,
			int maxResult, TItempic entity) throws Exception {
		String hql = "select o from TItempic o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TItempicDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	//修改
	@Override
	public void modifyService(TItempic entity) throws Exception {
		TItempicDao.modifyDao(entity);	
	}
	//添加
	@Override
	public void saveService(TItempic entity) throws Exception {
		TItempicDao.saveDao(entity);
	}
	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		TItempicDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public TItempic getByIdService(String id) throws Exception {
		return TItempicDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(TItempic entity) throws Exception {
		TItempicDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(TItempic entity) throws Exception {
		return TItempicDao.saveRetDao(entity);
	}
	public TItempicDao getTItempicDao() {
		return TItempicDao;
	}
	public void setTItempicDao(TItempicDao tItempicDao) {
		TItempicDao = tItempicDao;
	}
	@Override
	public List<TItempic> findServiceByRelItemID(String RelItemID)throws Exception {
		String hql = "select o from TItempic o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		whereHQL.append(" RelItemID = ? ");
		param.add(RelItemID);
		return TItempicDao.findDao(hql, whereHQL.toString(), param, orderby);
	}

}
